package com.nervenets.web.controller.user;

import com.nervenets.web.controller.TokenParams;
import com.nervenets.web.entity.UserToken;
import com.nervenets.web.enumeration.Gender;
import com.nervenets.web.enumeration.WealthType;
import com.nervenets.web.hibernate.domain.Manager;
import com.nervenets.web.hibernate.domain.user.User;
import com.nervenets.web.hibernate.domain.user.UserExtra;
import com.nervenets.web.redis.GlobalService;
import lombok.Data;

import java.io.Serializable;
import java.util.Set;

@Data
public class UserModel implements Serializable {
    private long id;
    private int createTime;
    private String openId;
    private Gender gender;
    private String mobile;
    private boolean enable;
    private int lastLoginTime;
    private UserExtra extra;
    private Set<Manager> teams;
    private String token;
    //统计数据
    private long surplus;//余额

    public UserModel(User user, GlobalService globalService) {
        this.id = user.getId();
        this.createTime = user.getCreateTime();
        this.openId = user.getOpenId();
        this.gender = user.getGender();
        this.mobile = user.getMobile();
        this.enable = user.isEnable();
        this.lastLoginTime = user.getLastLoginTime();
        this.extra = user.getExtra();
        this.teams = user.getTeams();

        this.token = TokenParams.getTokenStr(new UserToken(this.id));
        this.surplus = globalService.getUserWealthOfMoney(user.getId(), WealthType.money);
    }
}
